package com.example.mybatisplus.web.controller;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.stereotype.Controller;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.example.mybatisplus.common.JsonResponse;
import com.example.mybatisplus.service.VisitInfoService;
import com.example.mybatisplus.model.domain.VisitInfo;

import java.lang.reflect.Array;
import java.util.Arrays;
import java.util.List;


/**
 *
 *  前端控制器
 *
 *
 * @author lxp
 * @since 2023-10-16
 * @version v1.0
 */
@CrossOrigin
@Controller
@RequestMapping("/api/visitInfo")
public class VisitInfoController {

    private final Logger logger = LoggerFactory.getLogger( VisitInfoController.class );

    @Autowired
    private VisitInfoService visitInfoService;

    /**
    * 描述：根据Id 查询
    *
    */
    @RequestMapping(value = "/getAllById/{visitId}", method = RequestMethod.GET)
    @ResponseBody
    public JsonResponse getAllById(@PathVariable("visitId") Long visitId)throws Exception {
        VisitInfo  visitInfo =  visitInfoService.getAllById(visitId);
        return JsonResponse.success(visitInfo);
    }
    /*全部查询*/
    @RequestMapping("getTotal")
    @ResponseBody
    public JsonResponse getTotal(@RequestBody VisitInfo visitInfo){
        List<VisitInfo> visitInfos=visitInfoService.getTotal(visitInfo);
        return JsonResponse.success(visitInfos);
    }
    /*一次查出相应页数的数据并且可以模糊查询*/
    @RequestMapping(value="/getAll/{page}/{limit}")
    @ResponseBody
    public JsonResponse getAll(@PathVariable("page") Long page,@PathVariable("limit") Long limit,@RequestBody VisitInfo visitInfo){
        List<VisitInfo> visitInfos=visitInfoService.getAll(page,limit,visitInfo);
        return JsonResponse.success(visitInfos);
    }
    /*根据初访编号进行假删除多个删除*/
    @RequestMapping(value="/deleteByVisitIds")
    @ResponseBody
    public JsonResponse deleteByVisitIds(@RequestBody List<Long> visitIds) {
        visitInfoService.deleteByVisitIds(visitIds);
        return JsonResponse.success(null);
    }
    //审核
    @RequestMapping(value="/pass/{visitId}/{type}/{status}")
    @ResponseBody
    public JsonResponse passByVisitId(@PathVariable("visitId") Long visitId,@PathVariable("type") Long type,@PathVariable("status") Long status){
        visitInfoService.passByVisitId(visitId,type,status);
        return JsonResponse.success(null);
    }
    //修改初访信息
    @RequestMapping(value="/modifyInit")
    @ResponseBody
    public JsonResponse modifyInit(@RequestBody VisitInfo visitInfo){
        visitInfoService.modifyInit(visitInfo);
        return JsonResponse.success(null);
    }
    //初访员更新初访结论和详情
    @RequestMapping(value="/submitResult")
    @ResponseBody
    public JsonResponse modifyResult(@RequestBody VisitInfo visitInfo){
        visitInfoService.modifyResult(visitInfo);
        return JsonResponse.success(null);
    }
    //新增初访信息
    @RequestMapping(value="/addInit")
    @ResponseBody
    public JsonResponse addInit(@RequestBody VisitInfo visitInfo){
        visitInfoService.addInit(visitInfo);
        return JsonResponse.success(null);
    }
    //查询初访信息所对应的咨询信息
    @RequestMapping(value="/getInitCon")
    @ResponseBody
    public JsonResponse getInitCon(){
       List<VisitInfo> visitInfos=visitInfoService.getInitCon();
       return JsonResponse.success(visitInfos);
    }
    /**
    * 描述：根据Id 更新
    *
    */
    @RequestMapping(value = "", method = RequestMethod.PUT)
    @ResponseBody
    public JsonResponse updateVisitInfo(VisitInfo  visitInfo) throws Exception {
        visitInfoService.updateById(visitInfo);
        return JsonResponse.success(null);
    }


    /**
    * 描述:创建VisitInfo
    *
    */
    @RequestMapping(value = "", method = RequestMethod.POST)
    @ResponseBody
    public JsonResponse create(VisitInfo  visitInfo) throws Exception {
        visitInfoService.save(visitInfo);
        return JsonResponse.success(null);
    }
}

